{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 加载数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pandas import DataFrame\n",
    "from pandas import concat\n",
    "\n",
    "def series_to_supervised(data, n_in=1, n_out=1, dropnan=True):\n",
    "\t\"\"\"\n",
    "\tFrame a time series as a supervised learning dataset.\n",
    "\tArguments:\n",
    "\t\tdata: Sequence of observations as a list or NumPy array.\n",
    "\t\tn_in: Number of lag observations as input (X).\n",
    "\t\tn_out: Number of observations as output (y).\n",
    "\t\tdropnan: Boolean whether or not to drop rows with NaN values.\n",
    "\tReturns:\n",
    "\t\tPandas DataFrame of series framed for supervised learning.\n",
    "\t\"\"\"\n",
    "\tn_vars = 1 if type(data) is list else data.shape[1]\n",
    "\tdf = DataFrame(data)\n",
    "\tcols, names = list(), list()\n",
    "\t# input sequence (t-n, ... t-1)\n",
    "\tfor i in range(n_in, 0, -1):\n",
    "\t\tcols.append(df.shift(i))\n",
    "\t\tnames += [('var%d(t-%d)' % (j+1, i)) for j in range(n_vars)]\n",
    "\t# forecast sequence (t, t+1, ... t+n)\n",
    "\tfor i in range(0, n_out):\n",
    "\t\tcols.append(df.shift(-i))\n",
    "\t\tif i == 0:\n",
    "\t\t\tnames += [('var%d(t)' % (j+1)) for j in range(n_vars)]\n",
    "\t\telse:\n",
    "\t\t\tnames += [('var%d(t+%d)' % (j+1, i)) for j in range(n_vars)]\n",
    "\t# put it all together\n",
    "\tagg = concat(cols, axis=1)\n",
    "\tagg.columns = names\n",
    "\t# drop rows with NaN values\n",
    "\tif dropnan:\n",
    "\t\tagg.dropna(inplace=True)\n",
    "\treturn agg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "   var1(t-4)  var1(t-3)  var1(t-2)  var1(t-1)  var1(t)\n",
      "4        0.0        1.0        2.0        3.0        4\n",
      "5        1.0        2.0        3.0        4.0        5\n",
      "6        2.0        3.0        4.0        5.0        6\n",
      "7        3.0        4.0        5.0        6.0        7\n",
      "8        4.0        5.0        6.0        7.0        8\n",
      "9        5.0        6.0        7.0        8.0        9\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "(6, 5)\n"
     ]
    }
   ],
   "source": [
    "values = [x for x in range(10)]\n",
    "print(values)\n",
    "data = series_to_supervised(values, 4, 1)\n",
    "print(data)\n",
    "print(type(data))\n",
    "print(data.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   var1(t-4)  var1(t-3)  var1(t-2)  var1(t-1)\n",
      "4        0.0        1.0        2.0        3.0\n",
      "5        1.0        2.0        3.0        4.0\n",
      "6        2.0        3.0        4.0        5.0\n",
      "7        3.0        4.0        5.0        6.0\n",
      "8        4.0        5.0        6.0        7.0\n",
      "9        5.0        6.0        7.0        8.0\n",
      "=============================\n",
      "4    4\n",
      "5    5\n",
      "6    6\n",
      "7    7\n",
      "8    8\n",
      "9    9\n",
      "Name: var1(t), dtype: int64\n",
      "[[0. 1. 2. 3.]\n",
      " [1. 2. 3. 4.]\n",
      " [2. 3. 4. 5.]\n",
      " [3. 4. 5. 6.]\n",
      " [4. 5. 6. 7.]\n",
      " [5. 6. 7. 8.]]\n",
      "(6, 4)\n",
      "(6,)\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "处理数据\n",
    "'''\n",
    "train_x = data.iloc[:,:-1]#除了最后一列不要,代码还可以更加完善可读性高\n",
    "train_y = data.iloc[:,-1]\n",
    "print(train_x)\n",
    "print(\"=============================\")\n",
    "print(train_y)\n",
    "train_x = train_x.values#values才能reshape，否则AttributeError: 'DataFrame' object has no attribute 'reshape'\n",
    "train_y = train_y.values\n",
    "# train_x = train_x.reshape((train_x.shape[0], 1, train_x.shape[1]))#[hang,1,column]适合一个时间步多个变量也就是多个feature的打法\n",
    "# train_x = train_x.reshape(train_x.shape[0], train_x.shape[1], 1)#适合多个时间步单个变量也就是单个feature的打法\n",
    "# train_y = train_y.reshape(train_x.shape[0], 1,1 )\n",
    "\n",
    "print(train_x)\n",
    "print(train_x.shape)\n",
    "print(train_y.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import matplotlib.pyplot as plt\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense\n",
    "from keras.layers import LSTM\n",
    "import  pandas as pd\n",
    "import  os\n",
    "from keras.models import Sequential, load_model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def mkdir(path):\n",
    "    # 引入模块\n",
    "    import os\n",
    " \n",
    "    # 去除首位空格\n",
    "    path=path.strip()\n",
    "    # 去除尾部 \\ 符号\n",
    "    path=path.rstrip(\"\\\\\")\n",
    " \n",
    "    # 判断路径是否存在\n",
    "    # 存在     True\n",
    "    # 不存在   False\n",
    "    isExists=os.path.exists(path)\n",
    " \n",
    "    # 判断结果\n",
    "    if not isExists:\n",
    "        # 如果不存在则创建目录\n",
    "        # 创建目录操作函数\n",
    "        os.makedirs(path) \n",
    " \n",
    "        print (path+' 创建成功')\n",
    "        return True\n",
    "    else:\n",
    "        # 如果目录存在则不创建，并提示目录已存在\n",
    "        print (path+' 目录已存在')\n",
    "        return False\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "dense_30 (Dense)             (None, 125)               625       \n",
      "_________________________________________________________________\n",
      "dense_31 (Dense)             (None, 1)                 126       \n",
      "=================================================================\n",
      "Total params: 751\n",
      "Trainable params: 751\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Epoch 1/100\n",
      " - 0s - loss: 36.6960\n",
      "Epoch 2/100\n",
      " - 0s - loss: 16.4469\n",
      "Epoch 3/100\n",
      " - 0s - loss: 7.0564\n",
      "Epoch 4/100\n",
      " - 0s - loss: 1.8299\n",
      "Epoch 5/100\n",
      " - 0s - loss: 0.5212\n",
      "Epoch 6/100\n",
      " - 0s - loss: 0.7334\n",
      "Epoch 7/100\n",
      " - 0s - loss: 0.8585\n",
      "Epoch 8/100\n",
      " - 0s - loss: 0.6890\n",
      "Epoch 9/100\n",
      " - 0s - loss: 0.4503\n",
      "Epoch 10/100\n",
      " - 0s - loss: 0.2938\n",
      "Epoch 11/100\n",
      " - 0s - loss: 0.3149\n",
      "Epoch 12/100\n",
      " - 0s - loss: 0.3159\n",
      "Epoch 13/100\n",
      " - 0s - loss: 0.2987\n",
      "Epoch 14/100\n",
      " - 0s - loss: 0.2677\n",
      "Epoch 15/100\n",
      " - 0s - loss: 0.2849\n",
      "Epoch 16/100\n",
      " - 0s - loss: 0.2556\n",
      "Epoch 17/100\n",
      " - 0s - loss: 0.2441\n",
      "Epoch 18/100\n",
      " - 0s - loss: 0.2324\n",
      "Epoch 19/100\n",
      " - 0s - loss: 0.2299\n",
      "Epoch 20/100\n",
      " - 0s - loss: 0.2118\n",
      "Epoch 21/100\n",
      " - 0s - loss: 0.2054\n",
      "Epoch 22/100\n",
      " - 0s - loss: 0.1940\n",
      "Epoch 23/100\n",
      " - 0s - loss: 0.1892\n",
      "Epoch 24/100\n",
      " - 0s - loss: 0.1783\n",
      "Epoch 25/100\n",
      " - 0s - loss: 0.1751\n",
      "Epoch 26/100\n",
      " - 0s - loss: 0.1611\n",
      "Epoch 27/100\n",
      " - 0s - loss: 0.1490\n",
      "Epoch 28/100\n",
      " - 0s - loss: 0.1502\n",
      "Epoch 29/100\n",
      " - 0s - loss: 0.1405\n",
      "Epoch 30/100\n",
      " - 0s - loss: 0.1266\n",
      "Epoch 31/100\n",
      " - 0s - loss: 0.1246\n",
      "Epoch 32/100\n",
      " - 0s - loss: 0.1151\n",
      "Epoch 33/100\n",
      " - 0s - loss: 0.1112\n",
      "Epoch 34/100\n",
      " - 0s - loss: 0.0997\n",
      "Epoch 35/100\n",
      " - 0s - loss: 0.0962\n",
      "Epoch 36/100\n",
      " - 0s - loss: 0.0891\n",
      "Epoch 37/100\n",
      " - 0s - loss: 0.0898\n",
      "Epoch 38/100\n",
      " - 0s - loss: 0.0798\n",
      "Epoch 39/100\n",
      " - 0s - loss: 0.0739\n",
      "Epoch 40/100\n",
      " - 0s - loss: 0.0688\n",
      "Epoch 41/100\n",
      " - 0s - loss: 0.0655\n",
      "Epoch 42/100\n",
      " - 0s - loss: 0.0611\n",
      "Epoch 43/100\n",
      " - 0s - loss: 0.0594\n",
      "Epoch 44/100\n",
      " - 0s - loss: 0.0543\n",
      "Epoch 45/100\n",
      " - 0s - loss: 0.0484\n",
      "Epoch 46/100\n",
      " - 0s - loss: 0.0449\n",
      "Epoch 47/100\n",
      " - 0s - loss: 0.0428\n",
      "Epoch 48/100\n",
      " - 0s - loss: 0.0388\n",
      "Epoch 49/100\n",
      " - 0s - loss: 0.0362\n",
      "Epoch 50/100\n",
      " - 0s - loss: 0.0312\n",
      "Epoch 51/100\n",
      " - 0s - loss: 0.0293\n",
      "Epoch 52/100\n",
      " - 0s - loss: 0.0275\n",
      "Epoch 53/100\n",
      " - 0s - loss: 0.0257\n",
      "Epoch 54/100\n",
      " - 0s - loss: 0.0239\n",
      "Epoch 55/100\n",
      " - 0s - loss: 0.0209\n",
      "Epoch 56/100\n",
      " - 0s - loss: 0.0195\n",
      "Epoch 57/100\n",
      " - 0s - loss: 0.0171\n",
      "Epoch 58/100\n",
      " - 0s - loss: 0.0177\n",
      "Epoch 59/100\n",
      " - 0s - loss: 0.0150\n",
      "Epoch 60/100\n",
      " - 0s - loss: 0.0135\n",
      "Epoch 61/100\n",
      " - 0s - loss: 0.0117\n",
      "Epoch 62/100\n",
      " - 0s - loss: 0.0108\n",
      "Epoch 63/100\n",
      " - 0s - loss: 0.0096\n",
      "Epoch 64/100\n",
      " - 0s - loss: 0.0089\n",
      "Epoch 65/100\n",
      " - 0s - loss: 0.0086\n",
      "Epoch 66/100\n",
      " - 0s - loss: 0.0070\n",
      "Epoch 67/100\n",
      " - 0s - loss: 0.0065\n",
      "Epoch 68/100\n",
      " - 0s - loss: 0.0059\n",
      "Epoch 69/100\n",
      " - 0s - loss: 0.0055\n",
      "Epoch 70/100\n",
      " - 0s - loss: 0.0046\n",
      "Epoch 71/100\n",
      " - 0s - loss: 0.0043\n",
      "Epoch 72/100\n",
      " - 0s - loss: 0.0042\n",
      "Epoch 73/100\n",
      " - 0s - loss: 0.0033\n",
      "Epoch 74/100\n",
      " - 0s - loss: 0.0029\n",
      "Epoch 75/100\n",
      " - 0s - loss: 0.0028\n",
      "Epoch 76/100\n",
      " - 0s - loss: 0.0024\n",
      "Epoch 77/100\n",
      " - 0s - loss: 0.0022\n",
      "Epoch 78/100\n",
      " - 0s - loss: 0.0019\n",
      "Epoch 79/100\n",
      " - 0s - loss: 0.0016\n",
      "Epoch 80/100\n",
      " - 0s - loss: 0.0015\n",
      "Epoch 81/100\n",
      " - 0s - loss: 0.0013\n",
      "Epoch 82/100\n",
      " - 0s - loss: 0.0011\n",
      "Epoch 83/100\n",
      " - 0s - loss: 0.0010\n",
      "Epoch 84/100\n",
      " - 0s - loss: 8.5800e-04\n",
      "Epoch 85/100\n",
      " - 0s - loss: 8.4400e-04\n",
      "Epoch 86/100\n",
      " - 0s - loss: 7.0384e-04\n",
      "Epoch 87/100\n",
      " - 0s - loss: 5.6171e-04\n",
      "Epoch 88/100\n",
      " - 0s - loss: 5.5075e-04\n",
      "Epoch 89/100\n",
      " - 0s - loss: 4.6717e-04\n",
      "Epoch 90/100\n",
      " - 0s - loss: 4.2002e-04\n",
      "Epoch 91/100\n",
      " - 0s - loss: 3.7244e-04\n",
      "Epoch 92/100\n",
      " - 0s - loss: 3.1471e-04\n",
      "Epoch 93/100\n",
      " - 0s - loss: 2.7751e-04\n",
      "Epoch 94/100\n",
      " - 0s - loss: 2.0593e-04\n",
      "Epoch 95/100\n",
      " - 0s - loss: 2.0646e-04\n",
      "Epoch 96/100\n",
      " - 0s - loss: 1.8401e-04\n",
      "Epoch 97/100\n",
      " - 0s - loss: 1.3809e-04\n",
      "Epoch 98/100\n",
      " - 0s - loss: 1.4340e-04\n",
      "Epoch 99/100\n",
      " - 0s - loss: 1.2165e-04\n",
      "Epoch 100/100\n",
      " - 0s - loss: 1.0001e-04\n",
      "DATA 目录已存在\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Embedding,SimpleRNN\n",
    "model = Sequential()\n",
    "\n",
    "model = Sequential()\n",
    "# model.add(Embedding(10000,32))\n",
    "# model.add(SimpleRNN(32,input_shape=(train_x.shape[1], train_x.shape[2])))\n",
    "# model.add(LSTM(50, input_shape=(train_x.shape[1], train_x.shape[2])))\n",
    "model.add(Dense(125,input_shape=(train_x.shape[1],)))\n",
    "\n",
    "model.add(Dense(1))\n",
    "# model.add(layers.Dense(64, activation='relu',input_shape=(X_train.shape[1],)))\n",
    "model.summary()\n",
    "model.compile(loss='mean_squared_error', optimizer='adam')\n",
    "model.fit(train_x, train_y, epochs=100, batch_size=1, verbose=2)\n",
    "\n",
    "mkpath=\"DATA\" #保存模型的路径\n",
    "mkdir(mkpath)#创造文件夹\n",
    "model.save(os.path.join(\"DATA\",\"Test\" + \".h5\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0. 1. 2. 3.]\n",
      " [1. 2. 3. 4.]\n",
      " [2. 3. 4. 5.]\n",
      " [3. 4. 5. 6.]\n",
      " [4. 5. 6. 7.]\n",
      " [5. 6. 7. 8.]]\n",
      "===================\n",
      "[0. 1. 2. 3.]\n",
      "===================\n",
      "(4,)\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "Error when checking input: expected dense_26_input to have shape (4,) but got array with shape (1,)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_18804\\563578702.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[1;31m# predict_x = train_x[0].reshape(1,train_x.shape[1])#shape=(1,seq_length,dim) sample=1 很好理解\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      7\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpredict_x\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0my_train_pred_nn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpredict_x\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      9\u001b[0m \u001b[1;31m# y_train_pred_nn = model.predict(train_x)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my_train_pred_nn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\envs\\pytorch-gpu\\lib\\site-packages\\keras\\engine\\training.py\u001b[0m in \u001b[0;36mpredict\u001b[1;34m(self, x, batch_size, verbose, steps)\u001b[0m\n\u001b[0;32m   1147\u001b[0m                              'argument.')\n\u001b[0;32m   1148\u001b[0m         \u001b[1;31m# Validate user data.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1149\u001b[1;33m         \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_standardize_user_data\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1150\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstateful\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1151\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m>\u001b[0m \u001b[0mbatch_size\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0mbatch_size\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\envs\\pytorch-gpu\\lib\\site-packages\\keras\\engine\\training.py\u001b[0m in \u001b[0;36m_standardize_user_data\u001b[1;34m(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)\u001b[0m\n\u001b[0;32m    749\u001b[0m             \u001b[0mfeed_input_shapes\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    750\u001b[0m             \u001b[0mcheck_batch_axis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m  \u001b[1;31m# Don't enforce the batch size.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 751\u001b[1;33m             exception_prefix='input')\n\u001b[0m\u001b[0;32m    752\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    753\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0my\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\envs\\pytorch-gpu\\lib\\site-packages\\keras\\engine\\training_utils.py\u001b[0m in \u001b[0;36mstandardize_input_data\u001b[1;34m(data, names, shapes, check_batch_axis, exception_prefix)\u001b[0m\n\u001b[0;32m    136\u001b[0m                             \u001b[1;34m': expected '\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mnames\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m' to have shape '\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    137\u001b[0m                             \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m' but got array with shape '\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 138\u001b[1;33m                             str(data_shape))\n\u001b[0m\u001b[0;32m    139\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    140\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: Error when checking input: expected dense_26_input to have shape (4,) but got array with shape (1,)"
     ]
    }
   ],
   "source": [
    "print(train_x)\n",
    "print(\"===================\")\n",
    "print(train_x[0])\n",
    "print(\"===================\")\n",
    "predict_x = train_x[0]\n",
    "# predict_x = train_x[0].reshape(1,train_x.shape[1])#shape=(1,seq_length,dim) sample=1 很好理解\n",
    "print(predict_x.shape)\n",
    "y_train_pred_nn = model.predict(predict_x)\n",
    "# y_train_pred_nn = model.predict(train_x)\n",
    "print(y_train_pred_nn)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "ea70d47c1026074199160e48050b9f1be75d4ba7d6f2081b88238ca77789226b"
  },
  "kernelspec": {
   "display_name": "Python 3.7.11 ('pytorch-gpu')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
